package com.yc.sole.system.controller;

import com.yc.sole.framework.mybatis.page.BasePageReq;
import com.yc.sole.framework.mybatis.page.Paging;
import com.yc.sole.system.request.LogReq;
import com.yc.sole.framework.result.Result;
import com.yc.sole.framework.validate.DeleteGroup;
import com.yc.sole.framework.web.PreAuth;
import com.yc.sole.system.biz.LogBiz;
import com.yc.sole.system.request.LogQueryReq;
import com.yc.sole.system.response.LogResp;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 操作日志
 *
 * @author yizuomin
 * @date 2023-04-01
 **/
@Slf4j
@RestController
@RequiredArgsConstructor
public class LogController {

    private final LogBiz logBiz;

    /**
     * 通过id删除
     *
     * @param logReq
     * @return RestResult
     */
    @PreAuth(value = "system:log:delete", description = "删除操作日志")
    @PostMapping("/api/system/log/deleteLog")
    public Result<Void> deleteLog(@RequestBody @Validated(DeleteGroup.class) LogReq logReq) {
        logBiz.deleteLog(logReq.getIds());
        return Result.success();
    }


    /**
     * 分页查询
     *
     * @param basePageReq
     * @return Result
     */
    @PreAuth(value = "system:log:select", description = "分页查询操作日志")
    @PostMapping("/api/system/log/selectLogPage")
    public Result<Paging<LogResp>> selectLogPage(@RequestBody @Validated BasePageReq<LogQueryReq> basePageReq) {
        return Result.data(logBiz.selectLogPage(basePageReq.toPage(), basePageReq.getQuery()));
    }

    /**
     * 通过id查询日志详情
     *
     * @param logId
     * @return Result
     */
    @PreAuth(value = "system:log:select", description = "通过id查询日志详情")
    @PostMapping("/api/system/log/selectLogById/{logId}")
    public Result<LogResp> selectLogById(@PathVariable Long logId) {
        return Result.data(logBiz.selectLogById(logId));
    }
}
